package com.qfedu.service.impl;

import com.qfedu.entity.BoxEntity;
import com.qfedu.entity.OrderEntity;
import com.qfedu.mapper.OrderMapper;
import com.qfedu.service.OrderService;
import com.qfedu.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class OrderServiceimpl implements OrderService {
@Autowired(required = false)
    private OrderMapper orderMapper;
    @Override
    public Boolean insertOrder(OrderEntity orderEntity) {
        Boolean flag = orderMapper.insertOrder(orderEntity);
        return flag;
    }

    @Override
    public List<BoxEntity> selectBoxBySid(int sid) {
        List<BoxEntity> boxEntities = orderMapper.selectBoxBySid(sid);
        return boxEntities;
    }

    @Override
    public Boolean updateOrder(OrderEntity orderEntity) {
        Boolean aBoolean = orderMapper.updateOrder(orderEntity);
        return aBoolean;
    }

    @Override
    public Page queryByPage(int pageNum, int pageSize,int uid,String qutj,int ostatus) {
//        Page page = new Page(pageNum, pageSize);
//        //查询当前用户所有订单数量，
//        int count = orderMapper.queryordercount(uid);
//        page.setCount(count);
//        //获取首页
//        int instart = page.getStart();
//        //查询订单数量
//        List<OrderEntity> orderEntities = orderMapper.queryByUid(instart, pageSize, uid);
//        page.setOrderlist(orderEntities);

        Page page = new Page(pageNum, pageSize);
        Map<String, Object> map = new HashMap<>();
       if (uid!=0){
           map.put("uid",uid);
       }
        map.put("pageSize",pageSize);
        if (qutj!=null){
            map.put("qutj",qutj);
        }
        if (ostatus!=0){
            map.put("ostatus",ostatus);
        }
        int count=orderMapper.queryordercount(map);
        page.setCount(count);
        int instart=page.getStart();
        map.put("instart",instart);
        List<OrderEntity> orderEntities = orderMapper.queryByUid(map);
        page.setOrderlist(orderEntities);
        return page;
    }

    @Override
    public OrderEntity queryone(String oid) {
        OrderEntity queryone = orderMapper.queryone(oid);
        return queryone;
    }

    @Override
    public List<OrderEntity> queryAllOrder() {
//        List<OrderEntity> orderEntities = orderMapper.queryAllOrder();
//        return orderEntities;
    return null;
    }

    @Override
    public Page queryStatisPage(int pageNum,int pageSize) {
        Page page = new Page(pageNum,pageSize);
        List<OrderEntity> orderEntities = orderMapper.queryAllOrder(pageNum);
        page.setOrderlist(orderEntities);
        page.setCount(24);
        return page;
    }

    @Override
    public List<OrderEntity> queryStatisYear(int year) {
        List<OrderEntity> orderEntities = orderMapper.queryStatisYear(year);

        return orderEntities;
    }

    @Override
    public Boolean delByOid(String oid) {
        Boolean aBoolean = orderMapper.delByOid(oid);
        return aBoolean;
    }
}
